//
//  NineViewController.m
//  UI_元旦豆瓣小集合
//
//  Created by dllo on 16/1/9.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "NineViewController.h"
#import "ADataBaseHandle.h"
#import "Mytitlemodel.h"
#import "My1model.h"
@interface NineViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *tableview;
@property (nonatomic, retain)NSMutableArray *selectarray;

@end

@implementation NineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _tableview.dataSource = self;
    _tableview.delegate = self;
    [self.view addSubview:_tableview];
    [_tableview release];
   
    self.selectarray = [[ADataBaseHandle sharedDaseBaseHandle] selectModel];
//    for (Mytitlemodel *modal in _selectarray) {
//        NSLog(@"%@", modal.title);
//    }
//    NSLog(@"%@", _selectarray);
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _selectarray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        
    }
    cell.textLabel.text = _selectarray[indexPath.row];
    return cell;
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    Mytitlemodel *modal = [Mytitlemodel mytitlemodel];
    modal.title = _selectarray[indexPath.row];
    [[ADataBaseHandle sharedDaseBaseHandle] deleteModel:modal];
    
    [_selectarray removeObjectAtIndex:indexPath.row];
    [_tableview deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
